package teams;

import java.util.HashSet;
import java.util.Set;

import players.FutbolPlayer;
import players.Position;
import players.TitularPlayer;

/**
 * Representa la Formacion de un Equipo
 */
public class Formation {

    // constructor vacio para el Hibernate.
    protected Formation() {
    }

    // constructor
    public Formation(final Team team) {
        this.team = team;
        this.titularPlayers = new HashSet<TitularPlayer>();
        this.substitutes = new HashSet<FutbolPlayer>();
    }

    // Variables

    private Set<TitularPlayer> titularPlayers;

    private Set<FutbolPlayer> substitutes;

    private Team team;

    private Integer id;

    // Metodos

    /**
     * Este metodo agrega un titularPlayer(jugadorTitular) a la lista titularPlayers.
     */
    private void addTitularPlayer(final TitularPlayer titular) {
        this.getTitularPlayers().add(titular);
    }

    /**
     * Este metodo agrega 1 TitularPlayer a la lista titularPlayers (jugadores titulares) y elimina el jugador "j"
     * (recibido por parametro) de la lista substitutes (suplentes).
     * 
     * @param j
     * @param aPosition
     */
    public void updateFormation(final FutbolPlayer j, final Position aPosition) {
        this.addTitularPlayer(new TitularPlayer(j, aPosition));
        this.getSubstitutes().remove(j);
    }

    @Override
    public String toString() {
        String enter = System.getProperty("line.separator");

        return "Equipo: " + this.getTeam().toString() + enter + "Titulares: " + this.getTitularPlayers().toString()
                + enter + "Suplentes: " + this.getSubstitutes().toString();

    }

    // Getters y Setters
    public Set<TitularPlayer> getTitularPlayers() {
        return this.titularPlayers;
    }

    public void setTitularPlayers(final Set<TitularPlayer> titularPlayers) {
        this.titularPlayers = titularPlayers;
    }

    public Set<FutbolPlayer> getSubstitutes() {
        return this.substitutes;
    }

    public void setSubstitutes(final Set<FutbolPlayer> substitutes) {
        this.substitutes = substitutes;
    }

    public Team getTeam() {
        return this.team;
    }

    public void setTeam(final Team team) {
        this.team = team;
    }

    public void setId(final Integer id) {
        this.id = id;
    }

    public Integer getId() {
        return this.id;
    }

}
